package com.flying.pas.security.model;

import java.util.Date;
import java.util.List;

import com.flying.framework.annotation.ConstantEnum;
import com.flying.framework.annotation.Param;
import com.flying.framework.annotation.Property;
import com.flying.framework.annotation.ServiceField;
import com.flying.framework.annotation.ServiceFieldParam;
import com.flying.framework.data.Data;
import com.flying.framework.data.DataSerializable;
import com.flying.framework.metadata.Meta;

@SuppressWarnings("serial")
@Meta(id="t_menu",title="菜单", table="t_menu", primaryKeys={"menu_id"})
public class Menu extends Data implements DataSerializable {
	public final static String ENTITY_NAME = "t_menu";
	
	public final static String MENU_ID = "menu_id";
	public final static String PARENT_ID = "parent_id";
	public final static String NAME = "name";
	public final static String MODULE = "module";
	public final static String URL = "url";
	public final static String PERM_ID = "perm_id";
	public final static String REMARKS = "remarks";
	public final static String SORT_ID = "sort_id";
	public final static String STATUS = "status";
	public final static String CREATE_TIME = "create_time";
	public final static String CREATOR = "creator";
	public final static String UPDATE_TIME = "update_time";
	public final static String UPDATOR = "updator";
	public final static String IS_LEAF = "is_leaf";
	
	public enum MenuStatus implements ConstantEnum<Integer> {
		PREPARING(0, "准备中"), PUBLISHED(1, "已发布");
		
		public final int status;
		public final String remarks;
		
		MenuStatus(int status, String remarks) {
			this.status = status;
			this.remarks = remarks;
		}
		@Override
		public Integer value() {
			return status;
		}
		@Override
		public String text() {
			return remarks;
		}
	}
	
	public enum MenuIsLeaf implements ConstantEnum<Integer> {
		NO(0, "否"), YES(1, "是");
		
		public final int status;
		public final String remarks;
		
		MenuIsLeaf(int status, String remarks) {
			this.status = status;
			this.remarks = remarks;
		}
		@Override
		public Integer value() {
			return status;
		}
		@Override
		public String text() {
			return remarks;
		}
	}
	
	@Param(value=MENU_ID,   required=true,   maxlength=0,	desc="菜单ID" , 
			generator="com.flying.pas.model.Menu.menuId", 
			props= {@Property(name="type",value="hidden")})
	private Long menuId;
	
	@Param(value=PARENT_ID,   required=false,   maxlength=0,	desc="父菜单ID", 
			props= {@Property(name="type",value="hidden")} )
	private Long parentId;
	
	@Param(value=PERM_ID,   required=false,   maxlength=0,	desc="权限ID", 
			props= {@Property(name="type",value="hidden")} )
	private Long permId;
	
	@Param(value=NAME,   required=true,   maxlength=100,	desc="名称" )
	private String name;
	
	@Param(value=URL,   required=false,   maxlength=300,	desc="URL" )
	private String url;
	
	@Param(value=MODULE,   required=false,   maxlength=100,	desc="所属模块" )
	private String module;
	
	@Param(value=REMARKS,   required=false,   maxlength=500,	desc="说明" )
	private String remarks;
	
	@Param(value=SORT_ID,   required=false,   maxlength=0,	desc="排序" )
	private Integer sortId;
	
	@Param(value=STATUS,   required=false,   maxlength=0,	desc="状态" )
	private Integer status;
	
	@Param(value=IS_LEAF,   required=false,   maxlength=0,	desc="是否叶节点" )
	private Integer isLeaf;
	
	@Param(value=CREATE_TIME,   required=false,   maxlength=0,	desc="创建时间" )
	private Date createTime;
	
	@Param(value=CREATOR,   required=false,   maxlength=100,	desc="创建人" )
	private String creator;
	
	@Param(value=UPDATE_TIME,   required=false,   maxlength=0,	desc="修改时间" )
	private Date updateTime;
	
	@Param(value=UPDATOR,   required=false,   maxlength=100,	desc="修改人" )
	private String updator;
	
	@ServiceField(serviceId="PermService:findById", params={@ServiceFieldParam(param=Perm.PERM_ID, value="$"+PERM_ID)})
	@Param(value="perm",  desc="权限" )
	private Perm perm;
	
	@ServiceField(serviceId="MenuService:findChildren", params={@ServiceFieldParam(param=PARENT_ID, value="$"+MENU_ID)}, valueAttribute="rows")
	@Param(value="children",   required=false,   maxlength=400,	desc="子菜单" )
	private List<Menu> children;
	
	public Date getCreateTime() {
		return this.createTime;
	}
	
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	
	public String getCreator() {
		return this.creator;
	}
	
	public void setCreator(String creator) {
		this.creator = creator;
	}
	
	public Long getMenuId() {
		return this.menuId;
	}
	
	public void setMenuId(Long menuId) {
		this.menuId = menuId;
	}
	
	public String getModule() {
		return this.module;
	}
	
	public void setModule(String module) {
		this.module = module;
	}
	
	public String getName() {
		return this.name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public Long getParentId() {
		return this.parentId;
	}
	
	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}
	
	public Long getPermId() {
		return this.permId;
	}
	
	public void setPermId(Long permId) {
		this.permId = permId;
	}
	
	public String getRemarks() {
		return this.remarks;
	}
	
	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}
	
	public Integer getSortId() {
		return this.sortId;
	}
	
	public void setSortId(Integer sortId) {
		this.sortId = sortId;
	}
	
	public Integer getStatus() {
		return this.status;
	}
	
	public void setStatus(Integer status) {
		this.status = status;
	}
	
	public Date getUpdateTime() {
		return this.updateTime;
	}
	
	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}
	
	public String getUpdator() {
		return this.updator;
	}
	
	public void setUpdator(String updator) {
		this.updator = updator;
	}
	
	public String getUrl() {
		return this.url;
	}
	
	public void setUrl(String url) {
		this.url = url;
	}
	
	public Integer getIsLeaf() {
		return this.isLeaf;
	}
	
	public void setIsLeaf(Integer isLeaf) {
		this.isLeaf = isLeaf;
	}

	public Perm getPerm() {
		return perm;
	}

	public void setPerm(Perm perm) {
		this.perm = perm;
	}
	
	public List<Menu> getChildren() {
		return children;
	}

	public void setChildren(List<Menu> children) {
		this.children = children;
	}

	public String getPermName() {
		Perm p = this.getPerm();
		return p == null?null: p.getName();
	}
	
	public String getId() {
		return String.valueOf(this.getMenuId());
	}
	
	public String getText() {
		return this.getName();
	}
}